package top.cflwork.service.impl;

import com.xiaoleilu.hutool.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

import top.cflwork.dao.ShopDao;
import top.cflwork.vo.ShopVo;
import top.cflwork.service.ShopService;
import top.cflwork.common.SequenceId;


@Service
public class ShopServiceImpl implements ShopService {
	@Autowired
	private ShopDao shopDao;
    @Autowired
    private SequenceId sequenceId;
	@Override
    @Transactional
	public ShopVo get(String id){
		return shopDao.get(id);
	}
	
	@Override
    @Transactional
	public List<ShopVo> list(ShopVo shopVo){
		return shopDao.list(shopVo);
	}
	
	@Override
    @Transactional
	public long count(ShopVo shopVo){
		return shopDao.count(shopVo);
	}
	
	@Override
    @Transactional
	public int save(ShopVo shop){
	    shop.setId(sequenceId.nextId());
	    return shopDao.save(shop);
	}
	
	@Override
    @Transactional
	public int update(ShopVo shop){
		return shopDao.update(shop);
	}
	
	@Override
    @Transactional
	public int remove(String id){
		return shopDao.remove(id);
	}
	
	@Override
    @Transactional
	public int batchRemove(String[] ids){
		return shopDao.batchRemove(ids);
	}

    @Override
    @Transactional
    public int batchSave(List<ShopVo> shopList){
			shopList.forEach(e -> {
				e.setId(sequenceId.nextId());
				e.setCreateTime(DateUtil.now());
			});
        return shopDao.batchSave(shopList);
    }

	@Override
	@Transactional
	public List<ShopVo> shopListAll(){
		return shopDao.shopListAll();
	}
}
